home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / sprite.X11R3 / spriteCG6.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-19  |  13.1 KB  |  494 lines

  1. /*-
  2.  * spriteCG6C.c --
  3.  *    Functions to support the sun CG6 board as a memory frame buffer.
  4.  */
  5.  
  6. /************************************************************
  7.  * Copyright (c) 1989 by the Regents of the University of California
  8.  *
  9.  * Permission to use, copy, modify, and distribute this
  10.  * software and its documentation for any purpose and without
  11.  * fee is hereby granted, provided that the above copyright
  12.  * notice appear in all copies.  The University of California
  13.  * makes no representations about the suitability of this
  14.  * software for any purpose.  It is provided "as is" without
  15.  * express or implied warranty.
  16.  ********************************************************/
  17.  
  18. #ifndef    lint
  19. static char rcsid[] =
  20.     "";
  21. #endif
  22.  
  23. #include    "spriteddx.h"
  24. #include    "os.h"
  25. #include    "resource.h"
  26.  
  27. #include    <sys.h>
  28. #include    <kernel/vmSunConst.h>
  29.  
  30. #include    "colormap.h"
  31. #include    "colormapst.h"
  32.  
  33. #define    CG6_HEIGHT    900
  34. #define    CG6_WIDTH    1152
  35.  
  36. /* For the SPARCstation 1 */
  37. #define CG6_FB        0xffd80000
  38. #define    CG6_CMAP    0xffd1f000
  39. #define    CG6_FHC        0xffd1c000
  40. #define    CG6_THC        0xffd1d000
  41.  
  42. /*
  43.  * Colormap stuff
  44.  */
  45. static ColormapPtr spriteCG6InstalledMap;
  46.  
  47. /*
  48.  * Brooktree DAC
  49.  * Only topmost byte is active (but must be written as longword ...)
  50.  */
  51. typedef volatile struct {
  52.     unsigned int    addr;        /* colormap address register */
  53.     unsigned int    cmap;        /* colormap data register */
  54.     unsigned int    ctrl;        /* control register */
  55.     unsigned int    omap;        /* overlay map data register */
  56. } CG6Cmap;
  57.  
  58. extern int TellLostMap(), TellGainedMap();
  59.  
  60. #define    SET_CREG(reg, val)    ((reg) = ((val)<<24))
  61. #define SET_CMAP(i, r, g, b)    SET_CREG(cMap->addr, i);    \
  62.                 SET_CREG(cMap->cmap, r);    \
  63.                 SET_CREG(cMap->cmap, g);    \
  64.                 SET_CREG(cMap->cmap, b);
  65. #define    SET_CTRL(reg, val)    SET_CREG(cMap->addr, reg);    \
  66.                 SET_CREG(cMap->ctrl, val);
  67. #define SET_OVER(i, r, g, b)    SET_CREG(cMap->addr, i);    \
  68.                 SET_CREG(cMap->omap, r);    \
  69.                 SET_CREG(cMap->omap, g);    \
  70.                 SET_CREG(cMap->omap, b);
  71. static void
  72. spriteCG6UpdateColormap(pScreen, index, count, rmap, gmap, bmap)
  73.     ScreenPtr        pScreen;
  74.     int            index, count;
  75.     unsigned char    *rmap, *gmap, *bmap;
  76. {
  77.     volatile CG6Cmap    *cMap = (CG6Cmap *)spriteFbs[pScreen->myNum].cmap;
  78.  
  79.     /* update the memory copy */
  80.     rmap+=index; gmap+=index; bmap+=index;
  81.     SET_CREG(cMap->addr, index);
  82.     while(count--) {
  83.     SET_CREG(cMap->cmap, *rmap++);
  84.     SET_CREG(cMap->cmap, *gmap++);
  85.     SET_CREG(cMap->cmap, *bmap++);
  86.     }
  87. }
  88.  
  89. static void
  90. spriteCG6InitColormap(pScreen)
  91.     ScreenPtr        pScreen;
  92. {
  93.     volatile CG6Cmap    *cMap = (CG6Cmap *)spriteFbs[pScreen->myNum].cmap;
  94.  
  95.     SET_CTRL(4, 0xff);    /* read mask */
  96.     SET_CTRL(5, 0x00);    /* blink mask */
  97.     SET_CTRL(6, 0x70);    /* command reg */
  98.     SET_CTRL(7, 0x00);    /* test reg */
  99.     SET_OVER(0, 0xff, 0xff, 0x00);    /* overlay colors */
  100.     SET_OVER(1, 0x00, 0xff, 0xff);
  101.     SET_OVER(2, 0xff, 0x00, 0xff);
  102.     SET_OVER(3, 0xff, 0x00, 0x00);
  103.     /* command reg:
  104.      *    7    4:1 multiplexing
  105.      *    6    use color palette RAM
  106.      *    5:4    blink divisor (11 = 65536)
  107.      *    3:2    blink enable
  108.      *    1:0    overlay enable
  109.      */
  110. }
  111.  
  112. /*-
  113.  *-----------------------------------------------------------------------
  114.  * spriteCG6SaveScreen --
  115.  *    Preserve the color screen by turning on or off the video
  116.  *
  117.  * Results:
  118.  *    None.
  119.  *
  120.  * Side Effects:
  121.  *    Video state is switched
  122.  *
  123.  *-----------------------------------------------------------------------
  124.  */
  125. static Bool
  126. spriteCG6SaveScreen (pScreen, on)
  127.     ScreenPtr      pScreen;
  128.     Bool          on;
  129. {
  130.     volatile CG6Cmap    *cMap = (CG6Cmap *)spriteFbs[pScreen->myNum].cmap;
  131.  
  132.     if (on != SCREEN_SAVER_ON) {
  133.     SetTimeSinceLastInputEvent();
  134.     screenSaved = FALSE;
  135.     if(spriteCG6InstalledMap) {
  136.         Entry *pent = spriteCG6InstalledMap->red;
  137.         if(pent->fShared) {
  138.             SET_CMAP(0, pent->co.shco.red->color >> 8,
  139.                     pent->co.shco.green->color >> 8,
  140.                 pent->co.shco.blue->color >> 8);
  141.         } else {
  142.         SET_CMAP(0, pent->co.local.red >> 8,
  143.                 pent->co.local.red >> 8,
  144.                 pent->co.local.red >> 8);
  145.         }
  146.     } else {
  147.         SET_CMAP(0, 0, 0, 0xff);
  148.     }
  149.     SET_CTRL(4, 0xff);
  150.     } else {
  151.     screenSaved = TRUE;
  152.     SET_CMAP(0, 0, 0, 0);
  153.     SET_CTRL(4, 0x00);
  154.     }
  155.     return TRUE;
  156. }
  157.  
  158. /*-
  159.  *-----------------------------------------------------------------------
  160.  * spriteCG6CloseScreen --
  161.  *    called to ensure video is enabled when server exits.
  162.  *
  163.  * Results:
  164.  *    Screen is unsaved.
  165.  *
  166.  * Side Effects:
  167.  *    None
  168.  *
  169.  *-----------------------------------------------------------------------
  170.  */
  171. /*ARGSUSED*/
  172. static Bool
  173. spriteCG6CloseScreen(i, pScreen)
  174.     int        i;
  175.     ScreenPtr    pScreen;
  176. {
  177.     volatile CG6Cmap    *cMap = (CG6Cmap *)spriteFbs[pScreen->myNum].cmap;
  178.  
  179.     spriteCG6InstalledMap = NULL;
  180.     SET_CMAP(0x00, 0x00, 0x00, 0x00);
  181.     SET_CMAP(0xff, 0xff, 0xff, 0xff);
  182.     return ((* pScreen->SaveScreen)(pScreen, SCREEN_SAVER_OFF));
  183. }
  184.  
  185. /*-
  186.  *-----------------------------------------------------------------------
  187.  * spriteCG6InstallColormap --
  188.  *    Install given colormap.
  189.  *
  190.  * Results:
  191.  *    None
  192.  *
  193.  * Side Effects:
  194.  *    Existing map is uninstalled.
  195.  *    All clients requesting ColormapNotify are notified
  196.  *
  197.  *-----------------------------------------------------------------------
  198.  */
  199. static void
  200. spriteCG6InstallColormap(cmap)
  201.     ColormapPtr    cmap;
  202. {
  203.     register int    i;
  204.     register Entry    *pent = cmap->red;
  205.     unsigned char    rmap[256], gmap[256], bmap[256];
  206.  
  207.     if(cmap == spriteCG6InstalledMap)
  208.     return;
  209.     if(spriteCG6InstalledMap)
  210.     WalkTree(spriteCG6InstalledMap->pScreen, TellLostMap,
  211.          (char *) &(spriteCG6InstalledMap->mid));
  212.     for(i=0; i<cmap->pVisual->ColormapEntries; i++) {
  213.     if (pent->fShared) {
  214.         rmap[i] = pent->co.shco.red->color >> 8;
  215.         gmap[i] = pent->co.shco.green->color >> 8;
  216.         bmap[i] = pent->co.shco.blue->color >> 8;
  217.     }
  218.     else {
  219.         rmap[i] = pent->co.local.red >> 8;
  220.         gmap[i] = pent->co.local.green >> 8;
  221.         bmap[i] = pent->co.local.blue >> 8;
  222.     }
  223.     pent++;
  224.     }
  225.     spriteCG6InstalledMap = cmap;
  226.     spriteCG6UpdateColormap(cmap->pScreen, 0, 256, rmap, gmap, bmap);
  227.     WalkTree(cmap->pScreen, TellGainedMap, (char *) &(cmap->mid));
  228. }
  229.  
  230. /*-
  231.  *-----------------------------------------------------------------------
  232.  * spriteCG6UninstallColormap --
  233.  *    Uninstall given colormap.
  234.  *
  235.  * Results:
  236.  *    None
  237.  *
  238.  * Side Effects:
  239.  *    default map is installed
  240.  *    All clients requesting ColormapNotify are notified
  241.  *
  242.  *-----------------------------------------------------------------------
  243.  */
  244. static void
  245. spriteCG6UninstallColormap(cmap)
  246.     ColormapPtr    cmap;
  247. {
  248.     if(cmap == spriteCG6InstalledMap) {
  249.     Colormap defMapID = cmap->pScreen->defColormap;
  250.  
  251.     if (cmap->mid != defMapID) {
  252.         ColormapPtr defMap =
  253.         (ColormapPtr)LookupID(defMapID, RT_COLORMAP, RC_CORE);
  254.  
  255.         if (defMap)
  256.         spriteCG6InstallColormap(defMap);
  257.         else
  258.             ErrorF("spriteCG6: Can't find default colormap\n");
  259.     }
  260.     }
  261. }
  262.  
  263. /*-
  264.  *-----------------------------------------------------------------------
  265.  * spriteCG6ListInstalledColormaps --
  266.  *    Fills in the list with the IDs of the installed maps
  267.  *
  268.  * Results:
  269.  *    Returns the number of IDs in the list
  270.  *
  271.  * Side Effects:
  272.  *    None
  273.  *
  274.  *-----------------------------------------------------------------------
  275.  */
  276. /*ARGSUSED*/
  277. static int
  278. spriteCG6ListInstalledColormaps(pScreen, pCmapList)
  279.     ScreenPtr    pScreen;
  280.     Colormap    *pCmapList;
  281. {
  282.     *pCmapList = spriteCG6InstalledMap->mid;
  283.     return (1);
  284. }
  285.  
  286.  
  287. /*-
  288.  *-----------------------------------------------------------------------
  289.  * spriteCG6StoreColors --
  290.  *    Sets the pixels in pdefs into the specified map.
  291.  *
  292.  * Results:
  293.  *    None
  294.  *
  295.  * Side Effects:
  296.  *    None
  297.  *
  298.  *-----------------------------------------------------------------------
  299.  */
  300. static void
  301. spriteCG6StoreColors(pmap, ndef, pdefs)
  302.     ColormapPtr    pmap;
  303.     int        ndef;
  304.     xColorItem    *pdefs;
  305. {
  306.     switch(pmap->class) {
  307.     case PseudoColor:
  308.     if(pmap == spriteCG6InstalledMap) {
  309.         /* We only have a single colormap */
  310.         unsigned char    rmap[256], gmap[256], bmap[256];
  311.         int            index;
  312.  
  313.         while (ndef--) {
  314.         index = pdefs->pixel&0xff;
  315.         rmap[index] = (pdefs->red) >> 8;
  316.         gmap[index] = (pdefs->green) >> 8;
  317.         bmap[index] = (pdefs->blue) >> 8;
  318.          spriteCG6UpdateColormap(pmap->pScreen,
  319.                       index, 1, rmap, gmap, bmap);
  320.         pdefs++;
  321.         }
  322.     }
  323.     break;
  324.     case DirectColor:
  325.     default:
  326.     ErrorF("spriteCG6StoreColors: bad class %d\n", pmap->class);
  327.     break;
  328.     }
  329. }
  330.  
  331. /*-
  332.  *-----------------------------------------------------------------------
  333.  * spriteCG6ResolvePseudoColor --
  334.  *    Adjust specified RGB values to closest values hardware can do.
  335.  *
  336.  * Results:
  337.  *    Args are modified.
  338.  *
  339.  * Side Effects:
  340.  *    None
  341.  *
  342.  *-----------------------------------------------------------------------
  343.  */
  344. /*ARGSUSED*/
  345. static void
  346. spriteCG6ResolvePseudoColor(pRed, pGreen, pBlue, pVisual)
  347.     CARD16    *pRed, *pGreen, *pBlue;
  348.     VisualPtr    pVisual;
  349. {
  350.     *pRed &= 0xff00;
  351.     *pGreen &= 0xff00;
  352.     *pBlue &= 0xff00;
  353. }
  354.  
  355. /*-
  356.  *-----------------------------------------------------------------------
  357.  * spriteCG6Init --
  358.  *    Attempt to find and initialize a cg6 framebuffer used as mono
  359.  *
  360.  * Results:
  361.  *    TRUE if everything went ok. FALSE if not.
  362.  *
  363.  * Side Effects:
  364.  *    Most of the elements of the ScreenRec are filled in. Memory is
  365.  *    allocated for the frame buffer and the buffer is mapped. The
  366.  *    video is enabled for the frame buffer...
  367.  *
  368.  *-----------------------------------------------------------------------
  369.  */
  370. /*ARGSUSED*/
  371. static Bool
  372. spriteCG6Init (index, pScreen, argc, argv)
  373.     int              index;        /* The index of pScreen in the ScreenInfo */
  374.     ScreenPtr      pScreen;      /* The Screen to initialize */
  375.     int              argc;            /* The number of the Server's arguments. */
  376.     char          **argv;       /* The arguments themselves. Don't change! */
  377. {
  378.     CARD16    zero = 0, ones = ~0;
  379.  
  380.     if (!cfbScreenInit (index, pScreen, spriteFbs[index].fb,
  381.                 CG6_WIDTH, CG6_HEIGHT, 100))
  382.     return (FALSE);
  383.  
  384.     pScreen->SaveScreen    =            spriteCG6SaveScreen;
  385.     pScreen->RecolorCursor =             spriteRecolorCursor;
  386.  
  387. #ifndef STATIC_COLOR
  388.     pScreen->InstallColormap = spriteCG6InstallColormap;
  389.     pScreen->UninstallColormap = spriteCG6UninstallColormap;
  390.     pScreen->ListInstalledColormaps = spriteCG6ListInstalledColormaps;
  391.     pScreen->StoreColors = spriteCG6StoreColors;
  392.     pScreen->ResolveColor = spriteCG6ResolvePseudoColor;
  393. #endif
  394.  
  395.     spriteCG6InitColormap(pScreen);
  396.     {
  397.     ColormapPtr cmap = (ColormapPtr)LookupID(pScreen->defColormap,
  398.         RT_COLORMAP, RC_CORE);
  399.  
  400.     if (!cmap)
  401.         FatalError("Can't find default colormap\n");
  402.     if (AllocColor(cmap, &ones, &ones, &ones, &(pScreen->whitePixel), 0)
  403.         || AllocColor(cmap, &zero, &zero, &zero, &(pScreen->blackPixel), 0))
  404.         FatalError("Can't alloc black & white pixels in cfbScreeninit\n");
  405.     spriteCG6InstallColormap(cmap);
  406.     }
  407.  
  408.     spriteCG6SaveScreen( pScreen, SCREEN_SAVER_OFF );
  409.     spriteScreenInit (pScreen);
  410.  
  411.     return (TRUE);
  412. }
  413.  
  414. /*-
  415.  *--------------------------------------------------------------
  416.  * spriteCG6Switch --
  417.  *      Enable or disable color plane 
  418.  *
  419.  * Results:
  420.  *      Color plane enabled for select =0, disabled otherwise.
  421.  *
  422.  *--------------------------------------------------------------
  423.  */
  424. static void
  425. spriteCG6Switch ()
  426. {
  427. }
  428.  
  429. /*-
  430.  *-----------------------------------------------------------------------
  431.  * spriteCG6Probe --
  432.  *    Attempt to find and initialize a cg6 framebuffer used as mono
  433.  *
  434.  * Results:
  435.  *    TRUE if everything went ok. FALSE if not.
  436.  *
  437.  * Side Effects:
  438.  *    Memory is allocated for the frame buffer and the buffer is mapped.
  439.  *
  440.  *-----------------------------------------------------------------------
  441.  */
  442. Bool
  443. spriteCG6Probe(screenInfo, index, fbNum, argc, argv)
  444.     ScreenInfo      *screenInfo;    /* The screenInfo struct */
  445.     int              index;        /* The index of pScreen in the ScreenInfo */
  446.     int              fbNum;        /* Index into the sunFbData array */
  447.     int              argc;            /* The number of the Server's arguments. */
  448.     char          **argv;       /* The arguments themselves. Don't change! */
  449. {
  450.     Sys_MachineInfo    machType;
  451.     pointer          pFb, pCm;    /* preallocated VM */
  452.     Address          vFb, vCm;    /* kernel virtual addresses to poke */
  453.     unsigned int    bCm, oCm;    /* base&offset for segment for cmap */
  454.     unsigned int    sFb;        /* how much mem to alloc */
  455.  
  456.     if(strlen(argv[0]) < 4 || strcmp("Xcg6", argv[0]+strlen(argv[0])-4) != 0)
  457.     return FALSE;
  458.  
  459.     if(!spriteFbs[index].mapped) {
  460.     if(Sys_GetMachineInfo(sizeof(machType), &machType) != SUCCESS) {
  461.         return FALSE;
  462.     }
  463.     if(machType.architecture == SYS_SUN4) {
  464.         if(machType.type == SYS_SUN_4_C) {
  465.         vFb = (Address)CG6_FB;        /* sparc station */
  466.         vCm = (Address)CG6_CMAP;
  467.         }
  468.     } else {
  469.         return FALSE;
  470.     }
  471.  
  472.     sFb = (CG6_HEIGHT*CG6_WIDTH + VMMACH_SEG_SIZE - 1) / VMMACH_SEG_SIZE;
  473.     sFb *= VMMACH_SEG_SIZE;
  474.     pFb = (pointer)malloc(sFb + VMMACH_SEG_SIZE);
  475.     pCm = (pointer)malloc(2*VMMACH_SEG_SIZE);
  476.     oCm = (unsigned int)vCm -
  477.         ((unsigned int)vCm)/VMMACH_SEG_SIZE*VMMACH_SEG_SIZE;
  478.     vCm = (Address)(((unsigned int)vCm)/VMMACH_SEG_SIZE*VMMACH_SEG_SIZE);
  479.  
  480.     if(Vm_MapKernelIntoUser(vFb, sFb, pFb, &spriteFbs[index].fb) != SUCCESS)
  481.           { perror("VmMap"); return (FALSE); }
  482.     if(Vm_MapKernelIntoUser(vCm, VMMACH_SEG_SIZE, pCm, &bCm) != SUCCESS)
  483.           return (FALSE);
  484.     spriteFbs[index].cmap = (pointer)(bCm+oCm);
  485.     spriteFbs[index].mapped = TRUE;
  486.     }
  487.     if(AddScreen(spriteCG6Init, argc, argv) > index) {
  488.     screenInfo->screen[index].CloseScreen = spriteCG6CloseScreen;
  489.     return TRUE;
  490.     } else {
  491.     return FALSE;
  492.     }
  493. }
  494.